package tuvienna.jade.participant;

import jade.core.behaviours.WakerBehaviour;

import java.util.Iterator;

import tuvienna.jade.CentralRandom;

/**
 * This is a participant who will just go to the next random table
 *
 */
public class LazyParticipantAgent extends ParticipantAgent{

	private static final long serialVersionUID = -2464849240631427835L;
	
	protected void setup() {
		super.setup();		
		
		addBehaviour(new WakerBehaviour(this, 2000) {
			private static final long serialVersionUID = 1345642262433L;
			protected void handleElapsedTimeout() {
				int tableNo = CentralRandom.nextInt(tables.size());
				Iterator<TableInformation> tablesIterator =  tables.values().iterator();
				TableInformation table = tablesIterator.next();
				for (int i=0; i<tableNo;i++) {
					table = tablesIterator.next();
				}
				addBehaviour(new RegisterAtTableBehaviour(getAgent(), table.getAID()));
			}
		});
		
		addBehaviour(new WakerBehaviour(this, 60000) {
			private static final long serialVersionUID = 1345643264432L;
			protected void handleElapsedTimeout() {
				addBehaviour(new DeregisterAtTableBehaviour(getAgent(), getAgent().getTable()));
			}
		});
		


	}
	

}
